//
//  Associated.swift
//  Social
//
//  Created by 李响 on 2019/5/21.
//  Copyright © 2019 shengsheng. All rights reserved.
//

import Foundation

enum Associated {
    
    static func get<T>(_ object: Any, _ key: UnsafeRawPointer) -> T? {
        return objc_getAssociatedObject(object, key) as? T
    }
    
    static func setAssign<T>(_ object: Any, _ key: UnsafeRawPointer, _ value: T) {
        set(object, key, value, .OBJC_ASSOCIATION_ASSIGN)
    }
    
    static func setRetainedNonatomic<T>(_ object: Any, _ key: UnsafeRawPointer, _ value: T) {
        set(object, key, value, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
    }
    
    static func set<T>(_ object: Any, _ key: UnsafeRawPointer, _ value: T, _ type: objc_AssociationPolicy) {
        objc_setAssociatedObject(object, key, value, type)
    }
}
